﻿@{
    ViewData["Title"] = "Add Doc";
    var uinfo = new UserAuthAid(ViewContext.HttpContext).Get();
}
<style>
    .adf {
        margin: auto;
        max-width: 400px;
    }

        .adf textarea {
            height: 120px;
        }
</style>
<div class="container">
    <div class="row">
        <div class="col-12">
            <form class="adf my-5" onsubmit="return savedoc()">
                <div class="form-group">
                    <input type="text" class="form-control" name="DsName" placeholder="名称" maxlength="50" autofocus />
                    <small class="form-text text-muted">必填</small>
                </div>
                <div class="form-group">
                    <textarea class="form-control" name="DsRemark" placeholder="描述" maxlength="200"></textarea>
                </div>
                <div class="form-group">
                    <select class="custom-select" name="DsOpen">
                        <option value="1">公开（只读）</option>
                        <option value="0">私有</option>
                    </select>
                </div>
                <button type="submit" class="btn btn-primary">
                    <i class="fa fa-save"></i>&nbsp;保存
                </button>
            </form>
        </div>
    </div>
</div>
<input type="hidden" id="hid_uid" value="@uinfo.UserId" />
<script>
    function savedoc() {
        if ($('input[name="DsName"]').val().trim() != "") {
            $.ajax({
                url: "/doc/item/SaveDocSet?savetype=add",
                type: 'post',
                data: $('form').serialize(),
                success: function (data) {
                    if (data == "success") {
                        location.href = "/doc/user/" + $('#hid_uid').val();
                    } else {
                        alert(data);
                    }
                }
            })
        } else {
            var target = $('input[name="DsName"]')[0];
            jz.tip({
                target: target,
                content: "请输入名称",
                align: "top"
            });
            target.focus();
        }
        return false;
    }
</script>